home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-07-28 | 6.8 KB | 279 lines | [TEXT/MPS ] |
- /*
- File: VirtualHFSMacFile.cp
-
- Copyright: © 1991-1994 by Apple Computer, Inc.
- All rights reserved.
-
- Part of the AOCE Sample SMSAM Package. Consult the license
- which came with this software for your specific legal rights.
-
- */
-
-
-
- #ifndef __TYPES__
- #include <Types.h>
- #endif
-
- #ifndef __MEMORY__
- #include <Memory.h>
- #endif
-
- #ifndef __ERRORS__
- #include <Errors.h>
- #endif
-
- #ifndef __FILES__
- #include <Files.h>
- #endif
-
- #ifndef __VIRTUALMACFILE__
- #include "VirtualMacFile.h"
- #endif
-
- #ifndef __VIRTUALHFSMACFILE__
- #include "VirtualHFSMacFile.h"
- #endif
-
- #ifndef __UTILITIES__
- #include "Utilities.h"
- #endif
-
- #ifndef __DEBUGGINGGEAR__
- #include "DebuggingGear.h"
- #endif
-
- const short kUnopenedRefNum = -1;
-
- #pragma segment VirtualHFSFile
-
- /***********************************|****************************************/
-
- TVirtualHFSMacFile::TVirtualHFSMacFile ( const FSSpec& storage, OSType creator, OSType fileType):
- TVirtualMacFile (),
- fSpec ( storage ),
- fDFRefnum ( kUnopenedRefNum ),
- fRFRefnum ( kUnopenedRefNum ),
- fDisposeFile ( false )
- {
- ::FSpCreate(&((TVirtualHFSMacFile*)this)->fSpec,creator,fileType,smRoman);
- }
-
- //--------------------------------------------------------------------------------
-
- TVirtualHFSMacFile::~TVirtualHFSMacFile()
- {
- Close();
- if (fDisposeFile)
- FAILOSErr ( ::FSpDelete(&((TVirtualHFSMacFile*)this)->fSpec) );
- }
-
- //--------------------------------------------------------------------------------
- // Returns true if the file will be disposed of by the destructor
- Boolean TVirtualHFSMacFile::GetDisposeFile()
- {
- return fDisposeFile;
- }
-
- //--------------------------------------------------------------------------------
- // Set to true: file will be disposed of by the destructor
- // Set to false: file will remain on disk after this object is deleted
- void TVirtualHFSMacFile::SetDisposeFile(Boolean disposeFile)
- {
- fDisposeFile = disposeFile;
- }
-
- //--------------------------------------------------------------------------------
-
- OSErr TVirtualHFSMacFile::Open ()
- {
- OSErr err = noErr;
-
- if ( fDFRefnum == kUnopenedRefNum )
- err = ::FSpOpenDF(&((TVirtualHFSMacFile*)this)->fSpec,fsRdWrPerm, &fDFRefnum);
-
- if ( err == noErr && fRFRefnum == kUnopenedRefNum )
- err = ::FSpOpenRF(&((TVirtualHFSMacFile*)this)->fSpec,fsRdWrPerm, &fRFRefnum);
-
- return err;
- }
-
- //--------------------------------------------------------------------------------
-
- OSErr TVirtualHFSMacFile::Close ()
- {
- OSErr err1 = ::FSClose(fDFRefnum);
- fDFRefnum = kUnopenedRefNum;
-
- OSErr err2 = ::FSClose(fRFRefnum);
- fRFRefnum = kUnopenedRefNum;
-
- if (err1 == noErr)
- err1 = err2;
-
- return err1;
- }
-
- //--------------------------------------------------------------------------------
-
- OSErr TVirtualHFSMacFile::ReadData (void* buffer,long& count,TVirtualMacFile::ForkType whichFork)
- {
- return ::FSRead(GetRefNum(whichFork),&count, buffer);
- }
-
- //--------------------------------------------------------------------------------
-
- OSErr TVirtualHFSMacFile::WriteData (const void* buffer, long& count, TVirtualMacFile::ForkType whichFork)
- {
- return ::FSWrite(GetRefNum(whichFork),&count, buffer);
- }
-
- //--------------------------------------------------------------------------------
-
- OSErr TVirtualHFSMacFile::SetEnd (long logEof, TVirtualMacFile::ForkType whichFork)
- {
- return ::SetEOF (GetRefNum(whichFork),logEof);
- }
-
- //--------------------------------------------------------------------------------
-
- OSErr TVirtualHFSMacFile::GetEnd (long& logEof, TVirtualMacFile::ForkType whichFork) const
- {
- return ::GetEOF (GetRefNum(whichFork),&logEof);
- }
-
- //--------------------------------------------------------------------------------
-
- OSErr TVirtualHFSMacFile::SetPosition (short posMode, long posOff, TVirtualMacFile::ForkType whichFork)
- {
- return ::SetFPos (GetRefNum(whichFork),posMode,posOff);
- }
-
- //--------------------------------------------------------------------------------
-
- OSErr TVirtualHFSMacFile::GetPosition (long& filePos,TVirtualMacFile::ForkType whichFork) const
- {
- return ::GetFPos (GetRefNum(whichFork),&filePos);
- }
-
- //--------------------------------------------------------------------------------
-
- OSErr TVirtualHFSMacFile::SetFinderInfo (const FInfo& finderInfo)
- {
- return ::FSpSetFInfo(&((TVirtualHFSMacFile*)this)->fSpec,&finderInfo);
- }
-
- //--------------------------------------------------------------------------------
-
- OSErr TVirtualHFSMacFile::GetFinderInfo (FInfo& finderInfo) const
- {
- return ::FSpGetFInfo(&((TVirtualHFSMacFile*)this)->fSpec,&finderInfo);
- }
-
- //--------------------------------------------------------------------------------
-
- void TVirtualHFSMacFile::SetUserRef(long ref)
- {
- fUserRef = ref;
- }
-
- //--------------------------------------------------------------------------------
-
- long TVirtualHFSMacFile::GetUserRef() const
- {
- return fUserRef;
- }
-
- //--------------------------------------------------------------------------------
-
- OSErr TVirtualHFSMacFile::GetDate (unsigned long& dateTime,TVirtualMacFile::WhichDateType whichDate) const
- {
- HParamBlockRec paramBlock;
- FSSpec spec = fSpec;
-
- OSErr err = GetFileInfo(spec, paramBlock);
-
- if (whichDate == kCreationDate)
- dateTime = paramBlock.fileParam.ioFlCrDat;
- else
- dateTime = paramBlock.fileParam.ioFlMdDat;
-
- return err;
- }
-
- //--------------------------------------------------------------------------------
-
- OSErr TVirtualHFSMacFile::SetDate (unsigned long dateTime,TVirtualMacFile::WhichDateType whichDate)
- {
- HParamBlockRec paramBlock;
- FSSpec spec = fSpec;
-
- OSErr err = GetFileInfo(spec, paramBlock);
-
- if (whichDate == kCreationDate)
- paramBlock.fileParam.ioFlCrDat = dateTime;
- else
- paramBlock.fileParam.ioFlMdDat = dateTime;
-
- paramBlock.fileParam.ioDirID = spec.parID;
- if (err == noErr)
- err = PBHSetFInfo(¶mBlock, false);
- return err;
- }
-
- //--------------------------------------------------------------------------------
-
- OSErr TVirtualHFSMacFile::SetSpec ( const FSSpec& spec )
- {
- OSErr error = noErr;
-
- if ( fSpec.vRefNum == spec.vRefNum )
- {
- if ( spec.parID != fSpec.parID )
- {
- error = ::MoveHFSFile ( fSpec.vRefNum, fSpec.parID, fSpec.name, spec.parID );
-
- if ( !error )
- fSpec.parID = spec.parID;
- }
-
- error = ::FSpRename ( &fSpec, spec.name );
-
- if ( !error )
- ::PLstrcpy ( fSpec.name, spec.name );
- }
- else
- {
- error = nsvErr;
- }
-
- return error;
- }
-
- //--------------------------------------------------------------------------------
-
- OSErr TVirtualHFSMacFile::GetSpec ( FSSpec& spec ) const
- {
- spec = fSpec;
- return noErr;
- }
-
- /***********************************|****************************************/
-
- OSErr
- TVirtualHFSMacFile::WriteToDisk ( const FSSpec& spec )
- {
- return TVirtualMacFile::WriteToDisk ( spec );
- }
-
- /***********************************|****************************************/
-
- OSErr
- TVirtualHFSMacFile::WriteToDisk ()
- {
- return noErr; // we are already on the disk!
- }
-
- /***********************************|****************************************/
-
-